package com.quick.springbootquicky.controller.file;

import com.quick.springbootquicky.utils.AliyunOSSUtil;
import com.quick.springbootquicky.utils.Result;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

/**
 * 上传文件
 */
@RestController
public class FileUploadController {

    @PostMapping("/upload")
    public Result<String> upload(MultipartFile file) throws Exception {
        String originalFilename = file.getOriginalFilename();
        String fileName = UUID.randomUUID().toString().replaceAll("-","")+originalFilename.substring(originalFilename.lastIndexOf("."));
        //file.transferTo(new File("E:\\logs\\"+fileName));
        String url= AliyunOSSUtil.uploadFile(fileName, file.getInputStream());
        return Result.success("上传成功",url);
    }
}
